package com.htfyun.guowenagingscreen;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.provider.Settings;

/**
 * Created by sst on 2018/9/6.
 */

public class FTUtils {

    public static void startFTFloat(Context context) {

        boolean canStartOverlays = true;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            if(!Settings.canDrawOverlays(context.getApplicationContext())) {
                //启动Activity让用户授权

                canStartOverlays = false;

                Intent it = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION);
                it.setData(Uri.parse("package:" + context.getPackageName()));
                context.startActivity(it);
            }
        }

        if (canStartOverlays) {
            context.getApplicationContext().startService(new Intent(context.getApplicationContext(), FTFloatWindowService.class));
        }
    }

    public static void stopFTFloat(Context context) {
        context.getApplicationContext().stopService(new Intent(context.getApplicationContext(), FTFloatWindowService.class));
    }

    public static void startMainActivity(Context context) {
        FTUtils.startActivity(context, MainActivity.class);
    }


    public static void startActivity(Context context, Class<? extends Activity> cls) {
        Intent intent = new Intent(context, cls);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intent);
    }


}
